﻿package org.dm.3d.geom
{
	import flash.geom.Vector3D;
	/**
	 * ...
	 * @author Scott
	 */
	public class TransformRote
	{		
		public function TransformRote(v:Vector3D=null) 
		{
			
		}
		public static function rotateX(v:Vector3D = null,rx:Number=0):Vector3D 
		{
			var rel:Vector3D = (v == null)?new Vector3D():v.clone();
			var tempx:Number = Math.cos(rx)*rel.x - Math.sin(rx)*rel.z;
			var tempy:Number = Math.sin(rx)*rel.x + Math.cos(rx)*rel.z;
			rel.x = tempx;
			rel.z = tempy;
			return rel;
		}
		public static function rotateY(v:Vector3D = null,ry:Number=0):Vector3D 
		{
			var rel:Vector3D = (v == null)?new Vector3D():v.clone();
			var tempx:Number = Math.cos(ry) * rel.y - Math.sin(ry) * rel.z;
			var tempy:Number = Math.sin(ry) * rel.y + Math.cos(ry) * rel.z;
			rel.y = tempx;
			rel.z = tempy;
			return rel;
		}
		public static function rotateZ(v:Vector3D = null,rz:Number=0):Vector3D 
		{
			var rel:Vector3D = (v == null)?new Vector3D():v.clone();
			var tempx:Number = Math.cos(rz)*rel.x - Math.sin(rz)*rel.y;
			var tempy:Number = Math.sin(rz)*rel.x + Math.cos(rz)*rel.y;
			rel.x = tempx;
			rel.y = tempy;
			return rel;
		}
		public static function rotateXYZ(v:Vector3D = null, angle:Vector3D = null):Vector3D
		{
			//var rel:Vector3D = v.clone();
			var rel:Vector3D = (v == null)?new Vector3D():v.clone();
			if (angle == null) angle = new Vector3D();
			var tempx:Number = Math.cos(angle.x)*rel.x - Math.sin(angle.x)*rel.z;
			var tempy:Number = Math.sin(angle.x) * rel.x + Math.cos(angle.x) * rel.z;
			rel.x = tempx;
			rel.z = tempy;
			
			tempx = Math.cos(angle.y) * rel.y - Math.sin(angle.y) * rel.z;
			tempy = Math.sin(angle.y) * rel.y + Math.cos(angle.y) * rel.z;
			rel.y = tempx;
			rel.z = tempy;
			
			tempx = Math.cos(angle.z)*rel.x - Math.sin(angle.z)*rel.y;
			tempy = Math.sin(angle.z)*rel.x + Math.cos(angle.z)*rel.y;
			rel.x = tempx;
			rel.y = tempy;
			return rel;
		}
	}
	
}